<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>A Tree-Walk Interpreter &middot; Crafting Interpreters</title>

<!-- Tell mobile browsers we're optimized for them and they don't need to crop
     the viewport. -->
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" type="text/css" href="style.css" />

<!-- Oh, God, Source Code Pro is so beautiful it makes me want to cry. -->
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400|Source+Sans+Pro:300,400,600' rel='stylesheet' type='text/css'>

<link rel="icon" type="image/png" href="image/favicon.png" />
<script src="jquery-3.4.1.min.js"></script>
<script src="script.js"></script>

<!-- Google analytics -->
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-42804721-2', 'auto');
  ga('send', 'pageview');
</script>

</head>
<body id="top">

<!-- <div class="scrim"></div> -->
<nav class="wide">
  <a href="/"><img src="image/logotype.png" title="Crafting Interpreters"></a>
  <div class="contents">
<h2><small>II</small>A Tree-Walk Interpreter</h2>

<ul>
    <li><a href="scanning.html"><small>4</small>Scanning</a></li>
    <li><a href="representing-code.html"><small>5</small>Representing Code</a></li>
    <li><a href="parsing-expressions.html"><small>6</small>Parsing Expressions</a></li>
    <li><a href="evaluating-expressions.html"><small>7</small>Evaluating Expressions</a></li>
    <li><a href="statements-and-state.html"><small>8</small>Statements and State</a></li>
    <li><a href="control-flow.html"><small>9</small>Control Flow</a></li>
    <li><a href="functions.html"><small>10</small>Functions</a></li>
    <li><a href="resolving-and-binding.html"><small>11</small>Resolving and Binding</a></li>
    <li><a href="classes.html"><small>12</small>Classes</a></li>
    <li><a href="inheritance.html"><small>13</small>Inheritance</a></li>
</ul>


<div class="prev-next">
    <a href="the-lox-language.html" title="The Lox Language" class="left">&larr;&nbsp;Previous</a>
    <a href="contents.html" title="Table of Contents">&uarr;&nbsp;Up</a>
    <a href="scanning.html" title="Scanning" class="right">Next&nbsp;&rarr;</a>
</div>  </div>
</nav>

<nav class="narrow">
<a href="/"><img src="image/logotype.png" title="Crafting Interpreters"></a>
<a href="the-lox-language.html" title="The Lox Language" class="prev">←</a>
<a href="scanning.html" title="Scanning" class="next">→</a>
</nav>

<div class="page">
<div class="nav-wrapper">
<nav class="floating">
  <a href="/"><img src="image/logotype.png" title="Crafting Interpreters"></a>
  <div class="expandable">
<h2><small>II</small>A Tree-Walk Interpreter</h2>

<ul>
    <li><a href="scanning.html"><small>4</small>Scanning</a></li>
    <li><a href="representing-code.html"><small>5</small>Representing Code</a></li>
    <li><a href="parsing-expressions.html"><small>6</small>Parsing Expressions</a></li>
    <li><a href="evaluating-expressions.html"><small>7</small>Evaluating Expressions</a></li>
    <li><a href="statements-and-state.html"><small>8</small>Statements and State</a></li>
    <li><a href="control-flow.html"><small>9</small>Control Flow</a></li>
    <li><a href="functions.html"><small>10</small>Functions</a></li>
    <li><a href="resolving-and-binding.html"><small>11</small>Resolving and Binding</a></li>
    <li><a href="classes.html"><small>12</small>Classes</a></li>
    <li><a href="inheritance.html"><small>13</small>Inheritance</a></li>
</ul>


<div class="prev-next">
    <a href="the-lox-language.html" title="The Lox Language" class="left">&larr;&nbsp;Previous</a>
    <a href="contents.html" title="Table of Contents">&uarr;&nbsp;Up</a>
    <a href="scanning.html" title="Scanning" class="right">Next&nbsp;&rarr;</a>
</div>  </div>
  <a id="expand-nav">≡</a>
</nav>
</div>

<article class="chapter">

  <div class="number">II</div>
  <h1 class="part">A Tree-Walk Interpreter</h1>

<p>With this part, we begin jlox, the first of our two interpreters. Programming
languages are a huge topic with piles of concepts and terminology to cram into
your brain all at once. Programming language theory requires a level of mental
rigor that you probably haven&rsquo;t had to summon since your last calculus final.
(Fortunately there isn&rsquo;t too much theory in this book.)</p>
<p>Implementing an interpreter uses a few architectural tricks and design
patterns uncommon in other kinds of applications, so we&rsquo;ll be getting used to
the engineering side of things too. Given all of that, we&rsquo;ll keep the code we
have to write as simple and plain as possible.</p>
<p>In less than two thousand lines of clean Java code, we&rsquo;ll build a complete
interpreter for Lox that implements every single feature of the language,
exactly as we&rsquo;ve specified. The first few chapters work front-to-back through
the phases of the interpreter<span class="em">&mdash;</span><a href="scanning.html">scanning</a>, <a href="parsing-expressions.html">parsing</a>, and
<a href="evaluating-expressions.html">evaluating code</a>. After that, we add language features one at a time,
growing a simple calculator into a full-fledged scripting language.</p>

<footer>
<a href="scanning.html" class="next">
  Next Chapter: &ldquo;Scanning&rdquo; &rarr;
</a>
Handcrafted by Robert Nystrom&ensp;&mdash;&ensp;<a href="https://github.com/munificent/craftinginterpreters/blob/master/LICENSE" target="_blank">&copy; 2015&hairsp;&ndash;&hairsp;2021</a>
</footer>
</article>

</div>
</body>
</html>
